package comdemo.controller;


import comdemo.pojo.Orders;
import comdemo.pojo.Result;
import comdemo.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author 沈仁聪
 * @since 2025-08-19
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;


    /**
     * <p>
     * 获取所有的订单信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-19
     */
    @GetMapping
    public Result getOrder() {
        List<Orders> list = orderService.list();
        return Result.success(list);
    }

    /**
     * <p>
     * 添加订单信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-19
     */
    @PostMapping("/add")
    public Result addOrder(@RequestBody Orders orders) {
        orderService.save(orders);
        return Result.success();
    }


    /**
     * <p>
     * 修改订单信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-19
     */
    @PostMapping("/update")
    public Result updateOrder(@RequestBody Orders orders) {
        orderService.updateById(orders);
        return Result.success();
    }

    /**
     * <p>
     * 删除订单信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-19
     */
    @DeleteMapping("/delete")
    public Result deleteOrder(@RequestBody Orders orders) {
        orderService.removeById(orders);
        return Result.success();
    }
}
